<!DOCTYPE HTML>
<html lang="zh-CN">




<head>
    <meta charset="utf-8">
    <meta name="keywords" content="&#39;JavaNote_SpringMVC_Day02&#39;, 深度学习 故障诊断 Java">
    <meta name="description" content="河海大学 | 计算机与信息学院 | 信号与信息处理">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
    <meta name="renderer" content="webkit|ie-stand|ie-comp">
    <meta name="mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
    <!-- Global site tag (gtag.js) - Google Analytics -->


    <title>&#39;JavaNote_SpringMVC_Day02&#39; | 世庆的博客</title>
    <link rel="icon" type="image/png" href="/shiqing/favicon.png">

    <link rel="stylesheet" type="text/css" href="/shiqing/libs/awesome/css/all.css">
    <link rel="stylesheet" type="text/css" href="/shiqing/libs/materialize/materialize.min.css">
    <link rel="stylesheet" type="text/css" href="/shiqing/libs/aos/aos.css">
    <link rel="stylesheet" type="text/css" href="/shiqing/libs/animate/animate.min.css">
    <link rel="stylesheet" type="text/css" href="/shiqing/libs/lightGallery/css/lightgallery.min.css">
    <link rel="stylesheet" type="text/css" href="/shiqing/css/matery.css">
    <link rel="stylesheet" type="text/css" href="/shiqing/css/my.css">

    <script src="/shiqing/libs/jquery/jquery.min.js"></script>

    <script src="https://sdk.jinrishici.com/v2/browser/jinrishici.js" charset="utf-8"></script>
<meta name="generator" content="Hexo 6.3.0"></head>




    <body>
        <header class="navbar-fixed">
    <nav id="headNav" class="bg-color nav-transparent">
        <div id="navContainer" class="nav-wrapper container">
            <div class="brand-logo">
                <a href="/shiqing/" class="waves-effect waves-light">
                    
                    <img src="/shiqing/medias/logo.png" class="logo-img" alt="LOGO">
                    
                    <span class="logo-span">世庆的博客</span>
                </a>
            </div>
            

<a href="#" data-target="mobile-nav" class="sidenav-trigger button-collapse"><i class="fas fa-bars"></i></a>
<ul class="right nav-menu">
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="/shiqing/" class="waves-effect waves-light">
      
      <i class="fas fa-home" style="zoom: 0.6;"></i>
      
      <span>首页</span>
    </a>
    
  </li>
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="/shiqing/tags" class="waves-effect waves-light">
      
      <i class="fas fa-tags" style="zoom: 0.6;"></i>
      
      <span>标签</span>
    </a>
    
  </li>
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="/shiqing/categories" class="waves-effect waves-light">
      
      <i class="fas fa-bookmark" style="zoom: 0.6;"></i>
      
      <span>分类</span>
    </a>
    
  </li>
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="/shiqing/archives" class="waves-effect waves-light">
      
      <i class="fas fa-archive" style="zoom: 0.6;"></i>
      
      <span>归档</span>
    </a>
    
  </li>
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="/shiqing/about" class="waves-effect waves-light">
      
      <i class="fas fa-user-circle" style="zoom: 0.6;"></i>
      
      <span>关于</span>
    </a>
    
  </li>
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="/shiqing/contact" class="waves-effect waves-light">
      
      <i class="fas fa-comments" style="zoom: 0.6;"></i>
      
      <span>留言板</span>
    </a>
    
  </li>
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="/shiqing/friends" class="waves-effect waves-light">
      
      <i class="fas fa-address-book" style="zoom: 0.6;"></i>
      
      <span>友情链接</span>
    </a>
    
  </li>
  
  <li>
    <a href="#searchModal" class="modal-trigger waves-effect waves-light">
      <i id="searchIcon" class="fas fa-search" title="搜索" style="zoom: 0.85;"></i>
    </a>
  </li>
</ul>


<div id="mobile-nav" class="side-nav sidenav">

    <div class="mobile-head bg-color">
        
        <img src="/shiqing/medias/logo.png" class="logo-img circle responsive-img">
        
        <div class="logo-name">世庆的博客</div>
        <div class="logo-desc">
            
            河海大学 | 计算机与信息学院 | 信号与信息处理
            
        </div>
    </div>

    

    <ul class="menu-list mobile-menu-list">
        
        <li class="m-nav-item">
	  
		<a href="/shiqing/" class="waves-effect waves-light">
			
			    <i class="fa-fw fas fa-home"></i>
			
			首页
		</a>
          
        </li>
        
        <li class="m-nav-item">
	  
		<a href="/shiqing/tags" class="waves-effect waves-light">
			
			    <i class="fa-fw fas fa-tags"></i>
			
			标签
		</a>
          
        </li>
        
        <li class="m-nav-item">
	  
		<a href="/shiqing/categories" class="waves-effect waves-light">
			
			    <i class="fa-fw fas fa-bookmark"></i>
			
			分类
		</a>
          
        </li>
        
        <li class="m-nav-item">
	  
		<a href="/shiqing/archives" class="waves-effect waves-light">
			
			    <i class="fa-fw fas fa-archive"></i>
			
			归档
		</a>
          
        </li>
        
        <li class="m-nav-item">
	  
		<a href="/shiqing/about" class="waves-effect waves-light">
			
			    <i class="fa-fw fas fa-user-circle"></i>
			
			关于
		</a>
          
        </li>
        
        <li class="m-nav-item">
	  
		<a href="/shiqing/contact" class="waves-effect waves-light">
			
			    <i class="fa-fw fas fa-comments"></i>
			
			留言板
		</a>
          
        </li>
        
        <li class="m-nav-item">
	  
		<a href="/shiqing/friends" class="waves-effect waves-light">
			
			    <i class="fa-fw fas fa-address-book"></i>
			
			友情链接
		</a>
          
        </li>
        
        
        <li><div class="divider"></div></li>
        <li>
            <a href="https://github.com/sqtian-hhu/" class="waves-effect waves-light" target="_blank">
                <i class="fab fa-github-square fa-fw"></i>Fork Me
            </a>
        </li>
        
    </ul>
</div>


        </div>

        
            <style>
    .nav-transparent .github-corner {
        display: none !important;
    }

    .github-corner {
        position: absolute;
        z-index: 10;
        top: 0;
        right: 0;
        border: 0;
        transform: scale(1.1);
    }

    .github-corner svg {
        color: #0f9d58;
        fill: #fff;
        height: 64px;
        width: 64px;
    }

    .github-corner:hover .octo-arm {
        animation: a 0.56s ease-in-out;
    }

    .github-corner .octo-arm {
        animation: none;
    }

    @keyframes a {
        0%,
        to {
            transform: rotate(0);
        }
        20%,
        60% {
            transform: rotate(-25deg);
        }
        40%,
        80% {
            transform: rotate(10deg);
        }
    }
</style>

<a href="https://github.com/sqtian-hhu/" class="github-corner tooltipped hide-on-med-and-down" target="_blank"
   data-tooltip="Fork Me" data-position="left" data-delay="50">
    <svg viewBox="0 0 250 250" aria-hidden="true">
        <path d="M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z"></path>
        <path d="M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2"
              fill="currentColor" style="transform-origin: 130px 106px;" class="octo-arm"></path>
        <path d="M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z"
              fill="currentColor" class="octo-body"></path>
    </svg>
</a>
        
    </nav>

</header>

        



<div class="bg-cover pd-header post-cover" style="background-image: url('/shiqing/medias/featureimages/17.jpg')">
    <div class="container" style="right: 0px;left: 0px;">
        <div class="row">
            <div class="col s12 m12 l12">
                <div class="brand">
                    <h1 class="description center-align post-title">&#39;JavaNote_SpringMVC_Day02&#39;</h1>
                </div>
            </div>
        </div>
    </div>
</div>




<main class="post-container content">

    
    <link rel="stylesheet" href="/shiqing/libs/tocbot/tocbot.css">
<style>
    #articleContent h1::before,
    #articleContent h2::before,
    #articleContent h3::before,
    #articleContent h4::before,
    #articleContent h5::before,
    #articleContent h6::before {
        display: block;
        content: " ";
        height: 100px;
        margin-top: -100px;
        visibility: hidden;
    }

    #articleContent :focus {
        outline: none;
    }

    .toc-fixed {
        position: fixed;
        top: 64px;
    }

    .toc-widget {
        width: 345px;
        padding-left: 20px;
    }

    .toc-widget .toc-title {
        padding: 35px 0 15px 17px;
        font-size: 1.5rem;
        font-weight: bold;
        line-height: 1.5rem;
    }

    .toc-widget ol {
        padding: 0;
        list-style: none;
    }

    #toc-content {
        padding-bottom: 30px;
        overflow: auto;
    }

    #toc-content ol {
        padding-left: 10px;
    }

    #toc-content ol li {
        padding-left: 10px;
    }

    #toc-content .toc-link:hover {
        color: #42b983;
        font-weight: 700;
        text-decoration: underline;
    }

    #toc-content .toc-link::before {
        background-color: transparent;
        max-height: 25px;

        position: absolute;
        right: 23.5vw;
        display: block;
    }

    #toc-content .is-active-link {
        color: #42b983;
    }

    #floating-toc-btn {
        position: fixed;
        right: 15px;
        bottom: 76px;
        padding-top: 15px;
        margin-bottom: 0;
        z-index: 998;
    }

    #floating-toc-btn .btn-floating {
        width: 48px;
        height: 48px;
    }

    #floating-toc-btn .btn-floating i {
        line-height: 48px;
        font-size: 1.4rem;
    }
</style>
<div class="row">
    <div id="main-content" class="col s12 m12 l9">
        <!-- 文章内容详情 -->
<div id="artDetail">
    <div class="card">
        <div class="card-content article-info">
            <div class="row tag-cate">
                <div class="col s7">
                    
                    <div class="article-tag">
                        
                            <a href="/shiqing/tags/Java%E6%A1%86%E6%9E%B6/">
                                <span class="chip bg-color">Java框架</span>
                            </a>
                        
                    </div>
                    
                </div>
                <div class="col s5 right-align">
                    
                    <div class="post-cate">
                        <i class="fas fa-bookmark fa-fw icon-category"></i>
                        
                            <a href="/shiqing/categories/Java/" class="post-category">
                                Java
                            </a>
                        
                    </div>
                    
                </div>
            </div>

            <div class="post-info">
                
                <div class="post-date info-break-policy">
                    <i class="far fa-calendar-minus fa-fw"></i>发布日期:&nbsp;&nbsp;
                    2020-07-08
                </div>
                

                

                

                

                
            </div>
        </div>
        <hr class="clearfix">

        
        <!-- 是否加载使用自带的 prismjs. -->
        <link rel="stylesheet" href="/shiqing/libs/prism/prism.css">
        

        

        <div class="card-content article-card-content">
            <div id="articleContent">
                <h2 id="Day2"><a href="#Day2" class="headerlink" title="Day2"></a>Day2</h2><ol>
<li>搭建环境</li>
</ol>
<p>第一章： 响应数据与结果视图</p>
<ol>
<li><p>响应的返回值是String类型<br>发送请求-&gt;查出对象-&gt;model对象将数据存入request域中-&gt;页面显示</p>
<p> <a href="user/testString">testString</a><br/></p>
<p> @RequestMapping(“&#x2F;testString”)<br> public String testString(Model model){<br> System.out.println(“testString方法执行了”);<br><br> &#x2F;&#x2F;模拟从数据库中查询出user对象<br> User user &#x3D; new User();<br> user.setUsername(“呈呈”);<br> user.setAge(18);<br> user.setPassword(“1201”);<br><br> &#x2F;&#x2F;model对象存数据<br> model.addAttribute(“user”,user);<br><br><br> return “success”;<br> }</p>
</li>
</ol>
<span id="more"></span>

<ol start="2">
<li><p>响应返回值是void类型<br>什么不写默认会跳转到pages里的testVoid.jsp</p>
<p> <a href="user/testVoid">testVoid</a><br/></p>
<p> &#x2F;&#x2F;没有返回值的情况<br> &#x2F;&#x2F;请求转发是一次请求,不用编写项目的名称<br> &#x2F;&#x2F;重定向是两次请求,需要写项目名称<br> @RequestMapping(“&#x2F;testVoid”)<br> public void testVoid(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {<br> System.out.println(“testVoid方法执行了”);</p>
</li>
</ol>
<p>&#x2F;&#x2F;        &#x2F;&#x2F;第一种:手动写转发时系统不会再自动经过视图解析器找到路径,需要自己写路径<br>&#x2F;&#x2F;        request.getRequestDispatcher(“&#x2F;WEB-INF&#x2F;pages&#x2F;success.jsp”).forward(request,response);</p>
<p>&#x2F;&#x2F;        &#x2F;&#x2F;第二种:如果要重定向,要加上项目名字.<br>&#x2F;&#x2F;        &#x2F;&#x2F;重定向是重发了一次请求,是不能直接访问web-inf下的页面的<br>&#x2F;&#x2F;        response.sendRedirect(request.getContextPath()+”&#x2F;index.jsp”);</p>
<pre><code>    //设置中文乱码
    response.setCharacterEncoding(&quot;UTF-8&quot;);
    response.setContentType(&quot;text/html;charset=UTF-8&quot;);
    //第三种:直接进行响应,通过流打印
    response.getWriter().print(&quot;你好&quot;);

    return;

&#125;
</code></pre>
<ol start="3">
<li><p>响应返回值是ModelAndView类型</p>
<p> <a href="user/testModelAndView">testModelAndView</a><br/></p>
<p> @RequestMapping(“&#x2F;testModelAndView”)<br> public ModelAndView testModelAndView(){<br> System.out.println(“testModelAndView方法执行了”);<br><br> &#x2F;&#x2F;创建一个ModelAndView对象<br> ModelAndView mv &#x3D; new ModelAndView();<br><br> &#x2F;&#x2F;模拟从数据库中查询出user对象<br> User user &#x3D; new User();<br> user.setUsername(“呈呈”);<br> user.setAge(18);<br> user.setPassword(“1021”);<br><br> &#x2F;&#x2F;把user对象存储到mv对象中,其底层也会把user对象存入到request对象中<br> mv.addObject(“user”,user);<br><br> &#x2F;&#x2F;跳转页面<br> mv.setViewName(“success”);<br><br> return mv;<br> }</p>
</li>
<li><p>使用forward和redirect进行页面跳转<br>用得较少</p>
<p> <a href="user/testForwardOrRedirect">testForwardOrRedirect</a><br/></p>
<p> &#x2F;&#x2F;使用关键字的方式进行转发或者重定向</p>
<p> @RequestMapping(“&#x2F;testForwardOrRedirect”)<br> public String testForwardOrRedirect(Model model){<br> System.out.println(“testForwardOrRedirect方法执行了”);</p>
</li>
</ol>
<p>&#x2F;&#x2F;        &#x2F;&#x2F;请求的转发<br>&#x2F;&#x2F;        return “forward:&#x2F;WEB-INF&#x2F;pages&#x2F;success.jsp”;</p>
<pre><code>    //重定向,使用关键字的方式可以不用加项目名称,关键字方法自动做好了
    return &quot;redirect:/index.jsp&quot;;
&#125;
</code></pre>
<ol start="5">
<li>响应json数据之过滤静态资源</li>
</ol>
<p>ResponseBody响应json数据</p>
<pre><code>1. 在webapp.js下配置jquery.min.js文件

2. 在response.jsp中引用
&lt;head&gt;
    &lt;title&gt;response&lt;/title&gt;
    &lt;script src=&quot;js/jquery.min.js&quot;&gt;&lt;/script&gt;
&lt;/head&gt;

3. button事件

&lt;button id=&quot;btn&quot;&gt;发送ajax的请求&lt;/button&gt;
</code></pre>
<hr>
<pre><code>4. 设置点击事件
</code></pre>
<head>
    <title>response</title>
    <script src="js/jquery.min.js"></script>

<pre><code>&lt;script&gt;
    //页面加载,绑定单机事件
   $(function()&#123;
      $(&quot;#btn&quot;).click(function () &#123;
            // alert(&quot;hello btn&quot;);

          //发送ajax请求
          $.ajax(&#123;
             //编写json格式,设置属性和值
              url:&quot;user/testAjax&quot;,
              contentType:&quot;application/json;charset=UTF-8&quot;,
              data:&#39;&#123;&quot;username&quot;:&quot;呈呈&quot;,&quot;password&quot;:&quot;1201&quot;,&quot;age&quot;:18&#125;&#39;,
              dataType:&quot;json&quot;,
              type:&quot;post&quot;,
              success:function (data) &#123;
                    //data是服务器端响应的json的数据,进行解析
              &#125;
          &#125;);
      &#125;);
   &#125;);

&lt;/script&gt;
</code></pre>
</head>

<hr>
<pre><code>5. 在sprinfmvc.xml中设置不要拦截静态资源jquery.min.js

&lt;!--告诉前端配置器,哪些静态资源不拦截--&gt;
&lt;mvc:resources mapping=&quot;/js/**&quot; location=&quot;/js/&quot;/&gt;
&lt;mvc:resources mapping=&quot;/images/**&quot; location=&quot;/images/&quot;/&gt;
&lt;mvc:resources mapping=&quot;/css/**&quot; location=&quot;/css/&quot;/&gt;

6. 编写响应方法testAjax
//模拟异步请求响应
@RequestMapping(&quot;/testAjax&quot;)
public void testAjax(@RequestBody String body)&#123;
    System.out.println(&quot;testAjax方法执行了&quot;);
    System.out.println(body);
&#125;
</code></pre>
<hr>
<p>把客户端发来的json数据封装到user对象<br>    7. 添加导入坐标</p>
<pre><code>&lt;dependency&gt;
  &lt;groupId&gt;com.fasterxml.jackson.core&lt;/groupId&gt;
  &lt;artifactId&gt;jackson-databind&lt;/artifactId&gt;
  &lt;version&gt;2.9.0&lt;/version&gt;
&lt;/dependency&gt;

&lt;dependency&gt;
  &lt;groupId&gt;com.fasterxml.jackson.core&lt;/groupId&gt;
  &lt;artifactId&gt;jackson-core&lt;/artifactId&gt;
  &lt;version&gt;2.9.0&lt;/version&gt;
&lt;/dependency&gt;

&lt;dependency&gt;
  &lt;groupId&gt;com.fasterxml.jackson.core&lt;/groupId&gt;
  &lt;artifactId&gt;jackson-annotations&lt;/artifactId&gt;
  &lt;version&gt;2.9.0&lt;/version&gt;
&lt;/dependency&gt;

8. 编写方法

//模拟异步请求响应
@RequestMapping(&quot;/testAjax&quot;)
//前端发送的是json数据,RequestBody注解将json串转成了user
//后端返回的是user类型,ResponseBody注解将user转成了json串
public @ResponseBody User testAjax(@RequestBody User user)&#123;
    System.out.println(&quot;testAjax方法执行了&quot;);
    //客户端发送ajax的请求,传的是json字符串,后端把json字符串封装到user对象中
    System.out.println(user);
    //做响应,模拟查询数据库
    user.setUsername(&quot;大呈呈&quot;);
    user.setAge(20);
    //响应
    return user;
&#125;

9. 弹出窗口

                  success:function (data) &#123;
                    //data是服务器端响应的json的数据,进行解析
                  alert(data);
                  alert(data.username);
                  alert(data.password);
                  alert(data.age);
                  
                
</code></pre>
<h2 id="第二章-SpringMVC实现文件上传"><a href="#第二章-SpringMVC实现文件上传" class="headerlink" title="第二章: SpringMVC实现文件上传"></a>第二章: SpringMVC实现文件上传</h2><p>文件上传的必要前提<br>A form表单的enctype取值必须是: multipart&#x2F;form-data<br>                        enctype: 是表单请求正文的类型</p>
<p>B method 属性必须是 Post</p>
<p>C 提供一个文件选择域&lt;input type&#x3D;”file&#x2F;&gt;</p>
<ol>
<li><p>传统方式</p>
 <form action="user/fileUpload1" method="post" enctype="multipart/form-data">
     选择文件:<input type="file" name="upload"/><br/>
     <input type="submit" value="上传">
 </form></li>
</ol>
<hr>
<ol start="2">
<li><p>添加导入坐标</p>
<pre><code> &lt;dependency&gt;
     &lt;groupId&gt;commons-fileupload&lt;/groupId&gt;
     &lt;artifactId&gt;commons-fileupload&lt;/artifactId&gt;
     &lt;version&gt;1.3.1&lt;/version&gt;
 &lt;/dependency&gt;

 &lt;dependency&gt;
     &lt;groupId&gt;commons-io&lt;/groupId&gt;
     &lt;artifactId&gt;commons-io&lt;/artifactId&gt;
     &lt;version&gt;2.4&lt;/version&gt;
 &lt;/dependency&gt;
 
</code></pre>
</li>
<li><p>保存</p>
</li>
</ol>
<p>提交表单所有内容都会被封装到request里</p>
<pre><code>/**
 * 文件上传
 */

@RequestMapping(&quot;/fileUpload1&quot;)
public String fileUpload(HttpServletRequest request) throws Exception &#123;
    System.out.println(&quot;传统方式文件上传&quot;);

    //使用fileupload组件完成文件上传
    //上传的位置
    String path = request.getSession().getServletContext().getRealPath(&quot;/uploads/&quot;);
    //判断该路径是否存在
    File file = new File(path);
    if (!file.exists())&#123;
        //创建文件夹
        file.mkdirs();
    &#125;

    //解析request对象,获取上传文件项
    DiskFileItemFactory factory = new DiskFileItemFactory();
    ServletFileUpload upload = new ServletFileUpload(factory);
    //解析request
    List&lt;FileItem&gt; items = upload.parseRequest(request);
    //遍历
    for (FileItem item : items) &#123;
        //进行判断,当前item对象是否是上传文件项
        if (item.isFormField())&#123;
            //说明是普通表单项

        &#125;else &#123;
            //说明是上传文件项
            //获取上传文件的名称
            String fileName = item.getName(); //得到的是全路径C:\Users\HASEE\Desktop\2.jpg,保存有问题

            //切分字符串,以\切分

            String[] strings = fileName.split(&quot;\\\\&quot;);
            fileName = strings[strings.length-1];

            //把文件名称设置为唯一值,uuid
            String uuid = UUID.randomUUID().toString().replace(&quot;-&quot;, &quot;&quot;);
            fileName = uuid+&quot;_&quot;+fileName;

            //完成文件上传
            item.write(new File(path,fileName));
            //删除临时文件
            item.delete();

        &#125;
    &#125;

    return &quot;success&quot;;

&#125;
</code></pre>
<hr>
<p>最终保存在D:\Tomcat\apache-tomcat-8.5.54\webapps\com_sqtian_SpringMVCDay02_02fileUpload_war\uploads</p>
<p>&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;</p>
<h2 id="SpringMVC上传文件方式"><a href="#SpringMVC上传文件方式" class="headerlink" title="SpringMVC上传文件方式"></a>SpringMVC上传文件方式</h2><p>原理:<br>上传文件–&gt;request–&gt;前端控制器–&gt;配置文件解析器 解析request–&gt;返回上传文件对象给前端控制器–&gt;把上传文件项传给controller方法</p>
<p>上传方法中的参数名字必须和表单中的一样</p>
<p>配置文件解析器对象的id必须是multipartResolver</p>
<ol>
<li><p>添加表单</p>
 <h3>SpringMVC文件上传</h3>

 <form action="user/fileUpload2" method="post" enctype="multipart/form-data">
     选择文件:<input type="file" name="upload"/><br/>
     <input type="submit" value="上传">
 </form>
</li>
<li><p>在springMVC.xml里配置文件解析器</p>
 <!--配置文件解析器-->
 <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
     <!--设置上传文件大小-->
     <property name="maxUploadSize" value="10485760"/>
 </bean>
 </li>
<li><p>编写方法<br>&#x2F;**</p>
<ul>
<li>SpringMVC文件上传<br>  *&#x2F;</li>
</ul>
<p> @RequestMapping(“&#x2F;fileUpload2”)<br> &#x2F;&#x2F;MultipartFile 的名字必须和表单中upload一样<br> public String SpringMVCFileUpload(HttpServletRequest request, MultipartFile upload) throws Exception {<br>     System.out.println(“springMVC方式文件上传”);</p>
<pre><code> //使用fileupload组件完成文件上传
 //上传的位置
 String path = request.getSession().getServletContext().getRealPath(&quot;/uploads/&quot;);
 //判断该路径是否存在
 File file = new File(path);
 if (!file.exists())&#123;
     //创建文件夹
     file.mkdirs();
 &#125;


 //获取上传文件的名称
 String filename = upload.getOriginalFilename();//得到的是全路径C:\Users\HASEE\Desktop\2.jpg,保存有问题

 //把文件名称设置为唯一值,uuid
 String uuid = UUID.randomUUID().toString().replace(&quot;-&quot;, &quot;&quot;);
 filename = uuid+&quot;_&quot;+filename;

 //完成文件上传
 upload.transferTo(new File(path,filename));

 return &quot;success&quot;;
</code></pre>
<p> }</p>
</li>
</ol>
<hr>
<h2 id="springmvc跨服务器方式的文件上传"><a href="#springmvc跨服务器方式的文件上传" class="headerlink" title="springmvc跨服务器方式的文件上传"></a>springmvc跨服务器方式的文件上传</h2><p>有一个应用服务器springmvc, 一个文件上传服务器fileuploadserver<br>用户发送了上传文件请求给springmvc服务器,应该把他存到fileupload服务器里</p>
<ol>
<li><p>新建一个module,部署在fileupload服务器里</p>
</li>
<li><p>第三种上传表单</p>
 <h3>跨服务器文件上传</h3>

 <form action="user/fileUpload3" method="post" enctype="multipart/form-data">
     选择文件:<input type="file" name="upload"/><br/>
     <input type="submit" value="上传">
 </form>
</li>
<li><p>添加新的坐标<br> <dependency><br>     <groupId>com.sun.jersey</groupId><br>     <artifactId>jersey-core</artifactId><br>     <version>1.18.1</version><br> </dependency><br><br> <dependency><br>     <groupId>com.sun.jersey</groupId><br>     <artifactId>jersey-client</artifactId><br>     <version>1.18.1</version><br> </dependency></p>
</li>
<li><p>编写方法</p>
<p> &#x2F;**</p>
<ul>
<li>SpringMVC文件上传<br>  *&#x2F;</li>
</ul>
<p> @RequestMapping(“&#x2F;fileUpload3”)<br> &#x2F;&#x2F;MultipartFile 的名字必须和表单中upload一样<br> public String fileUpload3(MultipartFile upload) throws Exception {<br>     System.out.println(“跨服务器文件上传”);</p>
<pre><code> //定义上传文件服务器路径
 String path = &quot;http://localhost:8080/com_sqtian_SpringMVC_fileuploadserver_war/uploads/&quot;;

 //获取上传文件的名称
 String filename = upload.getOriginalFilename();//得到的是全路径C:\Users\HASEE\Desktop\2.jpg,保存有问题

 //把文件名称设置为唯一值,uuid
 String uuid = UUID.randomUUID().toString().replace(&quot;-&quot;, &quot;&quot;);
 filename = uuid+&quot;_&quot;+filename;

 //完成文件上传,跨服务器上传
 //创建客户端对象
 Client client = Client.create();
 //和上传服务器进行连接
 WebResource webResource = client.resource(path + filename);
 //上传文件,要字节数组
 webResource.put(upload.getBytes());

 return &quot;success&quot;;
</code></pre>
<p> }</p>
</li>
</ol>
<hr>
<p>总是报错,发现是tomcat配置文件里拒绝了http的put,要把tomcat&#x2F;conf&#x2F;web.xml里的readonly改成false<br>添加代码</p>
<!-- 使得服务器允许文件写入。-->
<pre><code>    &lt;init-param&gt;
        &lt;param-name&gt;readonly&lt;/param-name&gt;
        &lt;param-value&gt;false&lt;/param-value&gt;
    &lt;/init-param&gt;
</code></pre>
<hr>
<p>另外,要在D:\Tomcat\apache-tomcat-8.5.54\webapps\com_sqtian_SpringMVC_fileuploadserver_war下自己建一个uploads文件夹</p>
<h2 id="第三章-SpringMVC的异常处理"><a href="#第三章-SpringMVC的异常处理" class="headerlink" title="第三章 SpringMVC的异常处理"></a>第三章 SpringMVC的异常处理</h2><ol>
<li><p>异常处理思路<br>Controller调用service，service调用dao，异常但是向上抛出的，最终由DispatcherServlet找异常处理器进行异常的处理</p>
</li>
<li><p>SpringMVC的异常处理</p>
</li>
</ol>
<p>浏览器 –请求–&gt; 前端控制器 –请求–&gt; web –请求–&gt; service –请求–&gt; dao</p>
<p>dao –抛出异常–&gt; service –抛出异常–&gt; web –抛出异常–&gt; 前端控制器异常处理器组件 –&gt; 异常处理器处理异常 –&gt; 跳转到错误提示页面</p>
<pre><code>1. 编写自定义异常类(做提示信息的)
</code></pre>
<p>package com.sqtian.exception;</p>
<p>&#x2F;**<br> *</p>
<ul>
<li><p>自定义的一个异常类</p>
</li>
<li><p>@author sqtian</p>
</li>
<li><p>@create 2020-07-10-10:50<br> *&#x2F;<br>public class SysException extends Exception {</p>
<p> &#x2F;&#x2F;存储提示信息<br> private String message;</p>
<p> public SysException(String message) {<br> this.message &#x3D; message;<br> }</p>
<p> public String getMessage() {<br> return message;<br> }</p>
<p> public void setMessage(String message) {<br> this.message &#x3D; message;<br> }</p>
</li>
</ul>
<p>}</p>
<hr>
<pre><code>2. 编写异常处理器
</code></pre>
<p>public class SysExceptionResolver implements HandlerExceptionResolver {</p>
<pre><code>/**
 * 处理异常业务逻辑
 * @param httpServletRequest
 * @param httpServletResponse
 * @param o
 * @param e
 * @return
 */
@Override
public ModelAndView resolveException(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o, Exception e) &#123;
    //获取到异常对象
    SysException se = null;
    if (e instanceof SysException)&#123;
        se = (SysException) e;
    &#125;else&#123;
        se = new SysException(&quot;系统正在维护&quot;);
    &#125;

    //创建ModelAndView对象
    ModelAndView mv = new ModelAndView();
    mv.addObject(&quot;errorMsg&quot;,e.getMessage());
    mv.setViewName(&quot;error&quot;);
    return mv;
&#125;
</code></pre>
<p>}</p>
<hr>
<pre><code>3. 配置一次处理器(跳转到提示页面)

在springmvc.xml中配置
&lt;!--配置异常处理器,正常bean对象的配置方法--&gt;
&lt;bean id=&quot;sysExceptionResolver&quot; class=&quot;com.sqtian.exception.SysExceptionResolver&quot;&gt;&lt;/bean&gt;
</code></pre>
<hr>
<pre><code>error.jsp
</code></pre>
<p>&lt;%@ page contentType&#x3D;”text&#x2F;html;charset&#x3D;UTF-8” language&#x3D;”java” isELIgnored&#x3D;”false” %&gt;</p>
<html>
<head>
    <title>error</title>
</head>
<body>

<pre><code>$&#123;errorMsg&#125;
</code></pre>
</body>
</html>	

<hr>
<pre><code>&lt;h3&gt;异常处理&lt;/h3&gt;

&lt;a href=&quot;user/testException&quot;&gt;异常处理&lt;/a&gt;
</code></pre>
<hr>
<p>测试异常的方法</p>
<p>@Controller<br>@RequestMapping(“&#x2F;user”)<br>public class UserController {</p>
<pre><code>@RequestMapping(&quot;/testException&quot;)
public String testException() throws SysException &#123;
    System.out.println(&quot;testException执行了&quot;);

    try &#123;
        //模拟异常
        int a = 10/0;
    &#125; catch (Exception e) &#123;

        //打印异常信息
        e.printStackTrace();
        //抛出自定义异常信息
        throw new SysException(&quot;查询所有的用户出现了错误...&quot;);

    &#125;

    return &quot;success&quot;;
&#125;
</code></pre>
<p>}</p>
<hr>
<h2 id="第四章-springMVC拦截器"><a href="#第四章-springMVC拦截器" class="headerlink" title="第四章 springMVC拦截器"></a>第四章 springMVC拦截器</h2><p>spring MVC 的处理器拦截器类似于Servlet开发中的过滤器Filter，用于对处理器进行预处理和后处理<br>用户可以自己定义一些拦截器来实现特定的功能</p>
<p>过滤器是servlet规范中的一部分，任何java web 工程都可以用<br>拦截器是SpringMVC框架自己的。只有使用了SpringMVC框架的工程才能用</p>
<p>过滤器在url-pattern中配置了&#x2F;*之后，可以对所有要访问的资源拦截<br>拦截器只会拦截访问的控制器方法，如果访问的是jsp，html，css，image或js是不会进行拦截的</p>
<p>&lt;%@ page contentType&#x3D;”text&#x2F;html;charset&#x3D;UTF-8” language&#x3D;”java” %&gt;</p>
<html>
<head>
    <title>interceptor</title>
</head>
<body>

<pre><code>&lt;h3&gt;拦截器&lt;/h3&gt;
&lt;a href=&quot;user/testInterceptor&quot;&gt;拦截器&lt;/a&gt;
</code></pre>
</body>
</html>
--------------------------------------------------------------

<p>&#x2F;**</p>
<ul>
<li>@author sqtian</li>
<li>@create 2020-07-10-14:21<br> *&#x2F;</li>
</ul>
<p>@Controller<br>@RequestMapping(“&#x2F;user”)<br>public class UserController {</p>
<pre><code>@RequestMapping(&quot;/testInterceptor&quot;)
public String testInterceptor()&#123;

    System.out.println(&quot;testInterceptor方法执行了&quot;);

    return &quot;success&quot;;
&#125;
</code></pre>
<h2 id=""><a href="#" class="headerlink" title="}"></a>}</h2><ol>
<li>编写拦截器类, 实现HandlerInterceptor接口<br>package com.sqtian.interceptor;</li>
</ol>
<p>import org.springframework.web.servlet.HandlerInterceptor;<br>import org.springframework.web.servlet.ModelAndView;</p>
<p>import javax.servlet.http.HttpServletRequest;<br>import javax.servlet.http.HttpServletResponse;</p>
<p>&#x2F;**</p>
<ul>
<li>自定义拦截器</li>
<li>@author sqtian</li>
<li>@create 2020-07-10-14:34<br> *&#x2F;</li>
</ul>
<p>public class MyInterceptor1 implements HandlerInterceptor {</p>
<pre><code>/**
 * 预处理,controller方法执行前
 * @param request
 * @param response
 * @param handler
 * @return true 放行,执行下一个拦截器.如果没有下一个,则执行controller中的方法
 *          false 不放行
 * @throws Exception
 */
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception &#123;
    System.out.println(&quot;MyInterceptor1执行了----前1111&quot;);
</code></pre>
<p>&#x2F;&#x2F;        return false; 拦截请求,可以手动跳转<br>&#x2F;&#x2F;        request.getRequestDispatcher(“&#x2F;WEB-INF&#x2F;pages&#x2F;error.jsp”).forward(request,response);<br>        return true;<br>    }</p>
<pre><code>/**
 * 后处理方法, controller方法执行后,success.jsp执行之前
 * @param request
 * @param response
 * @param handler
 * @param modelAndView
 * @throws Exception
 */
@Override
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception &#123;
    System.out.println(&quot;MyInterceptor1执行了----后1111&quot;);
&#125;


/**
 * success.jsp页面执行后,该方法会执行
 * 释放资源,关闭流
 * @param request
 * @param response
 * @param handler
 * @param ex
 * @throws Exception
 */
@Override
public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception &#123;
    System.out.println(&quot;MyInterceptor1执行了----最后1111&quot;);

&#125;
</code></pre>
<h2 id="-1"><a href="#-1" class="headerlink" title="}"></a>}</h2><ol start="2">
<li><p>springmvc.xml中配置拦截器</p>
 <!--配置拦截器-->
<p> <a href="mvc:interceptors">mvc:interceptors</a><br> <!--配置第一个--><br> <a href="mvc:interceptor">mvc:interceptor</a><br>     <!--
         mapping是要拦截的方法
         exclude-mapping是不要拦截的方法
         --><br>     &lt;mvc:mapping path&#x3D;”&#x2F;user&#x2F;*”&#x2F;&gt;<br>     <!--配置拦截器对象--><br>     <bean class="com.sqtian.interceptor.MyInterceptor1"/><br> </mvc:interceptor><br><br> <!--配置第二个--><br> <a href="mvc:interceptor">mvc:interceptor</a><br>     <!--
         mapping是要拦截的方法
         exclude-mapping是不要拦截的方法
         --><br>     &lt;mvc:mapping path&#x3D;”&#x2F;**”&#x2F;&gt;<br>     <!--配置拦截器对象--><br>     <bean class="com.sqtian.interceptor.MyInterceptor2"/><br> </mvc:interceptor><br> </mvc:interceptors></p>
</li>
</ol>
<hr>
<p>执行顺序</p>
<p>MyInterceptor1执行了—-前1111<br>MyInterceptor1执行了—-前2222<br>testInterceptor方法执行了<br>MyInterceptor1执行了—-后2222<br>MyInterceptor1执行了—-后1111<br>success.jsp执行了<br>MyInterceptor1执行了—-最后2222<br>MyInterceptor1执行了—-最后1111</p>
<hr>

                
            </div>
            <hr/>

            

    <div class="reprint" id="reprint-statement">
        
            <div class="reprint__author">
                <span class="reprint-meta" style="font-weight: bold;">
                    <i class="fas fa-user">
                        文章作者:
                    </i>
                </span>
                <span class="reprint-info">
                    <a href="/shiqing/about" rel="external nofollow noreferrer">ShiQing</a>
                </span>
            </div>
            <div class="reprint__type">
                <span class="reprint-meta" style="font-weight: bold;">
                    <i class="fas fa-link">
                        文章链接:
                    </i>
                </span>
                <span class="reprint-info">
                    <a href="https://shiqing.gitee.io/shiqing/2020/07/08/java-kuang-jia/javanote-springmvc-day02/">https://shiqing.gitee.io/shiqing/2020/07/08/java-kuang-jia/javanote-springmvc-day02/</a>
                </span>
            </div>
            <div class="reprint__notice">
                <span class="reprint-meta" style="font-weight: bold;">
                    <i class="fas fa-copyright">
                        版权声明:
                    </i>
                </span>
                <span class="reprint-info">
                    本博客所有文章除特別声明外，均采用
                    <a href="https://creativecommons.org/licenses/by/4.0/deed.zh" rel="external nofollow noreferrer" target="_blank">CC BY 4.0</a>
                    许可协议。转载请注明来源
                    <a href="/shiqing/about" target="_blank">ShiQing</a>
                    !
                </span>
            </div>
        
    </div>

    <script async defer>
      document.addEventListener("copy", function (e) {
        let toastHTML = '<span>复制成功，请遵循本文的转载规则</span><button class="btn-flat toast-action" onclick="navToReprintStatement()" style="font-size: smaller">查看</a>';
        M.toast({html: toastHTML})
      });

      function navToReprintStatement() {
        $("html, body").animate({scrollTop: $("#reprint-statement").offset().top - 80}, 800);
      }
    </script>



            <div class="tag_share" style="display: block;">
                <div class="post-meta__tag-list" style="display: inline-block;">
                    
                        <div class="article-tag">
                            
                                <a href="/shiqing/tags/Java%E6%A1%86%E6%9E%B6/">
                                    <span class="chip bg-color">Java框架</span>
                                </a>
                            
                        </div>
                    
                </div>
                <div class="post_share" style="zoom: 80%; width: fit-content; display: inline-block; float: right; margin: -0.15rem 0;">
                    <link rel="stylesheet" type="text/css" href="/shiqing/libs/share/css/share.min.css">
<div id="article-share">

    
    <div class="social-share" data-sites="twitter,facebook,google,qq,qzone,wechat,weibo,douban,linkedin" data-wechat-qrcode-helper="<p>微信扫一扫即可分享！</p>"></div>
    <script src="/shiqing/libs/share/js/social-share.min.js"></script>
    

    

</div>

                </div>
            </div>
            
                <style>
    #reward {
        margin: 40px 0;
        text-align: center;
    }

    #reward .reward-link {
        font-size: 1.4rem;
        line-height: 38px;
    }

    #reward .btn-floating:hover {
        box-shadow: 0 6px 12px rgba(0, 0, 0, 0.2), 0 5px 15px rgba(0, 0, 0, 0.2);
    }

    #rewardModal {
        width: 320px;
        height: 350px;
    }

    #rewardModal .reward-title {
        margin: 15px auto;
        padding-bottom: 5px;
    }

    #rewardModal .modal-content {
        padding: 10px;
    }

    #rewardModal .close {
        position: absolute;
        right: 15px;
        top: 15px;
        color: rgba(0, 0, 0, 0.5);
        font-size: 1.3rem;
        line-height: 20px;
        cursor: pointer;
    }

    #rewardModal .close:hover {
        color: #ef5350;
        transform: scale(1.3);
        -moz-transform:scale(1.3);
        -webkit-transform:scale(1.3);
        -o-transform:scale(1.3);
    }

    #rewardModal .reward-tabs {
        margin: 0 auto;
        width: 210px;
    }

    .reward-tabs .tabs {
        height: 38px;
        margin: 10px auto;
        padding-left: 0;
    }

    .reward-content ul {
        padding-left: 0 !important;
    }

    .reward-tabs .tabs .tab {
        height: 38px;
        line-height: 38px;
    }

    .reward-tabs .tab a {
        color: #fff;
        background-color: #ccc;
    }

    .reward-tabs .tab a:hover {
        background-color: #ccc;
        color: #fff;
    }

    .reward-tabs .wechat-tab .active {
        color: #fff !important;
        background-color: #22AB38 !important;
    }

    .reward-tabs .alipay-tab .active {
        color: #fff !important;
        background-color: #019FE8 !important;
    }

    .reward-tabs .reward-img {
        width: 210px;
        height: 210px;
    }
</style>

<div id="reward">
    <a href="#rewardModal" class="reward-link modal-trigger btn-floating btn-medium waves-effect waves-light red">赏</a>

    <!-- Modal Structure -->
    <div id="rewardModal" class="modal">
        <div class="modal-content">
            <a class="close modal-close"><i class="fas fa-times"></i></a>
            <h4 class="reward-title">你的赏识是我前进的动力</h4>
            <div class="reward-content">
                <div class="reward-tabs">
                    <ul class="tabs row">
                        <li class="tab col s6 alipay-tab waves-effect waves-light"><a href="#alipay">支付宝</a></li>
                        <li class="tab col s6 wechat-tab waves-effect waves-light"><a href="#wechat">微 信</a></li>
                    </ul>
                    <div id="alipay">
                        <img src="/shiqing/medias/reward/alipay.jpg" class="reward-img" alt="支付宝打赏二维码">
                    </div>
                    <div id="wechat">
                        <img src="/shiqing/medias/reward/wechat.png" class="reward-img" alt="微信打赏二维码">
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<script>
    $(function () {
        $('.tabs').tabs();
    });
</script>

            
        </div>
    </div>

    

    

    

    

    

    

    

    

<article id="prenext-posts" class="prev-next articles">
    <div class="row article-row">
        
        <div class="article col s12 m6" data-aos="fade-up">
            <div class="article-badge left-badge text-color">
                <i class="fas fa-chevron-left"></i>&nbsp;上一篇</div>
            <div class="card">
                <a href="/shiqing/2020/07/08/java-kuang-jia/javanote-ssm/">
                    <div class="card-image">
                        
                        
                        <img src="/shiqing/medias/featureimages/10.jpg" class="responsive-img" alt="&#39;JavaNote_SpringMVC_Day03&#39;">
                        
                        <span class="card-title">&#39;JavaNote_SpringMVC_Day03&#39;</span>
                    </div>
                </a>
                <div class="card-content article-content">
                    <div class="summary block-with-text">
                        
                            Day3 SSM三大框架整合第一步：搭建整合环境SSM整合可以使用多种方式，我们选用XML+注解的方式
整合思路：    1. 搭建环境    2. 搭建Spring配置    3. 使用Spring整合SpringMVC框架    4. 
                        
                    </div>
                    <div class="publish-info">
                        <span class="publish-date">
                            <i class="far fa-clock fa-fw icon-date"></i>2020-07-08
                        </span>
                        <span class="publish-author">
                            
                            <i class="fas fa-bookmark fa-fw icon-category"></i>
                            
                            <a href="/shiqing/categories/Java/" class="post-category">
                                    Java
                                </a>
                            
                            
                        </span>
                    </div>
                </div>
                
                <div class="card-action article-tags">
                    
                    <a href="/shiqing/tags/Java%E6%A1%86%E6%9E%B6/">
                        <span class="chip bg-color">Java框架</span>
                    </a>
                    
                </div>
                
            </div>
        </div>
        
        
        <div class="article col s12 m6" data-aos="fade-up">
            <div class="article-badge right-badge text-color">
                下一篇&nbsp;<i class="fas fa-chevron-right"></i>
            </div>
            <div class="card">
                <a href="/shiqing/2020/07/08/java-kuang-jia/javanote-springmvc-day01/">
                    <div class="card-image">
                        
                        
                        <img src="/shiqing/medias/featureimages/0.jpg" class="responsive-img" alt="&#39;JavaNote_SpringMVC_Day01&#39;">
                        
                        <span class="card-title">&#39;JavaNote_SpringMVC_Day01&#39;</span>
                    </div>
                </a>
                <div class="card-content article-content">
                    <div class="summary block-with-text">
                        
                            day1第一章：SpringMVC的基本概念开发架构一般基于两种形式：C&#x2F;S架构和B&#x2F;S架构。JavaEE开发中几乎全都是基于B&#x2F;S架构的开发。B&#x2F;S架构中，标准的三层架构包括：表现层、业务层、持久层
                        
                    </div>
                    <div class="publish-info">
                            <span class="publish-date">
                                <i class="far fa-clock fa-fw icon-date"></i>2020-07-08
                            </span>
                        <span class="publish-author">
                            
                            <i class="fas fa-bookmark fa-fw icon-category"></i>
                            
                            <a href="/shiqing/categories/Java/" class="post-category">
                                    Java
                                </a>
                            
                            
                        </span>
                    </div>
                </div>
                
                <div class="card-action article-tags">
                    
                    <a href="/shiqing/tags/Java%E6%A1%86%E6%9E%B6/">
                        <span class="chip bg-color">Java框架</span>
                    </a>
                    
                </div>
                
            </div>
        </div>
        
    </div>
</article>

</div>



<!-- 代码块功能依赖 -->
<script type="text/javascript" src="/shiqing/libs/codeBlock/codeBlockFuction.js"></script>

<!-- 代码语言 -->

<script type="text/javascript" src="/shiqing/libs/codeBlock/codeLang.js"></script>


<!-- 代码块复制 -->

<script type="text/javascript" src="/shiqing/libs/codeBlock/codeCopy.js"></script>


<!-- 代码块收缩 -->

<script type="text/javascript" src="/shiqing/libs/codeBlock/codeShrink.js"></script>


    </div>
    <div id="toc-aside" class="expanded col l3 hide-on-med-and-down">
        <div class="toc-widget card" style="background-color: white;">
            <div class="toc-title"><i class="far fa-list-alt"></i>&nbsp;&nbsp;目录</div>
            <div id="toc-content"></div>
        </div>
    </div>
</div>

<!-- TOC 悬浮按钮. -->

<div id="floating-toc-btn" class="hide-on-med-and-down">
    <a class="btn-floating btn-large bg-color">
        <i class="fas fa-list-ul"></i>
    </a>
</div>


<script src="/shiqing/libs/tocbot/tocbot.min.js"></script>
<script>
    $(function () {
        tocbot.init({
            tocSelector: '#toc-content',
            contentSelector: '#articleContent',
            headingsOffset: -($(window).height() * 0.4 - 45),
            collapseDepth: Number('0'),
            headingSelector: 'h2, h3, h4'
        });

        // modify the toc link href to support Chinese.
        let i = 0;
        let tocHeading = 'toc-heading-';
        $('#toc-content a').each(function () {
            $(this).attr('href', '#' + tocHeading + (++i));
        });

        // modify the heading title id to support Chinese.
        i = 0;
        $('#articleContent').children('h2, h3, h4').each(function () {
            $(this).attr('id', tocHeading + (++i));
        });

        // Set scroll toc fixed.
        let tocHeight = parseInt($(window).height() * 0.4 - 64);
        let $tocWidget = $('.toc-widget');
        $(window).scroll(function () {
            let scroll = $(window).scrollTop();
            /* add post toc fixed. */
            if (scroll > tocHeight) {
                $tocWidget.addClass('toc-fixed');
            } else {
                $tocWidget.removeClass('toc-fixed');
            }
        });

        
        /* 修复文章卡片 div 的宽度. */
        let fixPostCardWidth = function (srcId, targetId) {
            let srcDiv = $('#' + srcId);
            if (srcDiv.length === 0) {
                return;
            }

            let w = srcDiv.width();
            if (w >= 450) {
                w = w + 21;
            } else if (w >= 350 && w < 450) {
                w = w + 18;
            } else if (w >= 300 && w < 350) {
                w = w + 16;
            } else {
                w = w + 14;
            }
            $('#' + targetId).width(w);
        };

        // 切换TOC目录展开收缩的相关操作.
        const expandedClass = 'expanded';
        let $tocAside = $('#toc-aside');
        let $mainContent = $('#main-content');
        $('#floating-toc-btn .btn-floating').click(function () {
            if ($tocAside.hasClass(expandedClass)) {
                $tocAside.removeClass(expandedClass).hide();
                $mainContent.removeClass('l9');
            } else {
                $tocAside.addClass(expandedClass).show();
                $mainContent.addClass('l9');
            }
            fixPostCardWidth('artDetail', 'prenext-posts');
        });
        
    });
</script>

    

</main>




        <footer class="page-footer bg-color">
    
    <div class="container row center-align" style="margin-bottom: 0px !important;">
        <div class="col s12 m8 l8 copy-right">
            Copyright&nbsp;&copy;
            
                <span id="year">2019-2024</span>
            
            <span id="year">2019</span>
            <a href="/shiqing/about" target="_blank">ShiQing</a>
            |&nbsp;Powered by&nbsp;<a href="https://hexo.io/" target="_blank">Hexo</a>
            |&nbsp;Theme&nbsp;<a href="https://github.com/blinkfox/hexo-theme-matery" target="_blank">Matery</a>
            <br>
            
            
            
            
            
            
            <span id="busuanzi_container_site_pv">
                |&nbsp;<i class="far fa-eye"></i>&nbsp;总访问量:&nbsp;<span id="busuanzi_value_site_pv"
                    class="white-color"></span>&nbsp;次
            </span>
            
            
            <span id="busuanzi_container_site_uv">
                |&nbsp;<i class="fas fa-users"></i>&nbsp;总访问人数:&nbsp;<span id="busuanzi_value_site_uv"
                    class="white-color"></span>&nbsp;人
            </span>
            
            <br>
            
            <br>
            
        </div>
        <div class="col s12 m4 l4 social-link social-statis">
    <a href="https://github.com/blinkfox" class="tooltipped" target="_blank" data-tooltip="访问我的GitHub" data-position="top" data-delay="50">
        <i class="fab fa-github"></i>
    </a>



    <a href="mailto:2528393970@qq.com" class="tooltipped" target="_blank" data-tooltip="邮件联系我" data-position="top" data-delay="50">
        <i class="fas fa-envelope-open"></i>
    </a>



    <a href="tencent://AddContact/?fromId=50&fromSubId=1&subcmd=all&uin=2528393970" class="tooltipped" target="_blank" data-tooltip="QQ联系我: 2528393970" data-position="top" data-delay="50">
        <i class="fab fa-qq"></i>
    </a>







    <a href="/shiqing/atom.xml" class="tooltipped" target="_blank" data-tooltip="RSS 订阅" data-position="top" data-delay="50">
        <i class="fas fa-rss"></i>
    </a>

</div>
    </div>
</footer>

<div class="progress-bar"></div>


        <!-- 搜索遮罩框 -->
<div id="searchModal" class="modal">
    <div class="modal-content">
        <div class="search-header">
            <span class="title"><i class="fas fa-search"></i>&nbsp;&nbsp;搜索</span>
            <input type="search" id="searchInput" name="s" placeholder="请输入搜索的关键字"
                   class="search-input">
        </div>
        <div id="searchResult"></div>
    </div>
</div>

<script type="text/javascript">
$(function () {
    var searchFunc = function (path, search_id, content_id) {
        'use strict';
        $.ajax({
            url: path,
            dataType: "xml",
            success: function (xmlResponse) {
                // get the contents from search data
                var datas = $("entry", xmlResponse).map(function () {
                    return {
                        title: $("title", this).text(),
                        content: $("content", this).text(),
                        url: $("url", this).text()
                    };
                }).get();
                var $input = document.getElementById(search_id);
                var $resultContent = document.getElementById(content_id);
                $input.addEventListener('input', function () {
                    var str = '<ul class=\"search-result-list\">';
                    var keywords = this.value.trim().toLowerCase().split(/[\s\-]+/);
                    $resultContent.innerHTML = "";
                    if (this.value.trim().length <= 0) {
                        return;
                    }
                    // perform local searching
                    datas.forEach(function (data) {
                        var isMatch = true;
                        var data_title = data.title.trim().toLowerCase();
                        var data_content = data.content.trim().replace(/<[^>]+>/g, "").toLowerCase();
                        var data_url = data.url;
                        data_url = data_url.indexOf('/') === 0 ? data.url : '/' + data_url;
                        var index_title = -1;
                        var index_content = -1;
                        var first_occur = -1;
                        // only match artiles with not empty titles and contents
                        if (data_title !== '' && data_content !== '') {
                            keywords.forEach(function (keyword, i) {
                                index_title = data_title.indexOf(keyword);
                                index_content = data_content.indexOf(keyword);
                                if (index_title < 0 && index_content < 0) {
                                    isMatch = false;
                                } else {
                                    if (index_content < 0) {
                                        index_content = 0;
                                    }
                                    if (i === 0) {
                                        first_occur = index_content;
                                    }
                                }
                            });
                        }
                        // show search results
                        if (isMatch) {
                            str += "<li><a href='" + data_url + "' class='search-result-title'>" + data_title + "</a>";
                            var content = data.content.trim().replace(/<[^>]+>/g, "");
                            if (first_occur >= 0) {
                                // cut out 100 characters
                                var start = first_occur - 20;
                                var end = first_occur + 80;
                                if (start < 0) {
                                    start = 0;
                                }
                                if (start === 0) {
                                    end = 100;
                                }
                                if (end > content.length) {
                                    end = content.length;
                                }
                                var match_content = content.substr(start, end);
                                // highlight all keywords
                                keywords.forEach(function (keyword) {
                                    var regS = new RegExp(keyword, "gi");
                                    match_content = match_content.replace(regS, "<em class=\"search-keyword\">" + keyword + "</em>");
                                });

                                str += "<p class=\"search-result\">" + match_content + "...</p>"
                            }
                            str += "</li>";
                        }
                    });
                    str += "</ul>";
                    $resultContent.innerHTML = str;
                });
            }
        });
    };

    searchFunc('/shiqing/search.xml', 'searchInput', 'searchResult');
});
</script>

        <!-- 回到顶部按钮 -->
<div id="backTop" class="top-scroll">
    <a class="btn-floating btn-large waves-effect waves-light" href="#!">
        <i class="fas fa-arrow-up"></i>
    </a>
</div>


        <script src="/shiqing/libs/materialize/materialize.min.js"></script>
        <script src="/shiqing/libs/masonry/masonry.pkgd.min.js"></script>
        <script src="/shiqing/libs/aos/aos.js"></script>
        <script src="/shiqing/libs/scrollprogress/scrollProgress.min.js"></script>
        <script src="/shiqing/libs/lightGallery/js/lightgallery-all.min.js"></script>
        <script src="/shiqing/js/matery.js"></script>

        <!-- Baidu Analytics -->

        <!-- Baidu Push -->

<script>
    (function () {
        var bp = document.createElement('script');
        var curProtocol = window.location.protocol.split(':')[0];
        if (curProtocol === 'https') {
            bp.src = 'https://zz.bdstatic.com/linksubmit/push.js';
        } else {
            bp.src = 'http://push.zhanzhang.baidu.com/push.js';
        }
        var s = document.getElementsByTagName("script")[0];
        s.parentNode.insertBefore(bp, s);
    })();
</script>

        
        <script src="/shiqing/libs/others/clicklove.js" async="async"></script>
        
        
        <script async src="/shiqing/libs/others/busuanzi.pure.mini.js"></script>
        

        <script type="text/javascript">
            var OriginTitile = document.title,
                st;
            document.addEventListener("visibilitychange", function () {
                document.hidden ? (document.title = "看不见我~看不见我~", clearTimeout(st)) : (document.title =
                    "(๑•̀ㅂ•́) ✧被发现了～", st = setTimeout(function () {
                        document.title = OriginTitile
                    }, 3e3))
            })
        </script>

        <!-- 背景樱花飘落特效 -->
        
            <script type="text/javascript">
                //只在桌面版网页启用特效
                var windowWidth = $(window).width();
                if (windowWidth > 768) {
                    document.write('<script type="text/javascript" src="/js/xuehuapiaoluo.js"><\/script>');
                }
            </script>
        

        

        


        
        

        

        

        
        <script src="/shiqing/libs/instantpage/instantpage.js" type="module"></script>
        

    </body>

</html>
